<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${config.mapperConfig.packageUrl}.${table.modelName}${config.mapperConfig.fileSuffixName}" >
  <resultMap id="BaseResultMap" type="${config.modelConfig.packageUrl}.${table.modelName}" >
  <#list columnList as column>
  	<#if column.columnKey=='PRI'>
  	<id column="${column.columnName}" property="${column.propertyName}"/>	
  	</#if>
	<#if column.columnKey!='PRI'>
	<result column="${column.columnName}" property="${column.propertyName}"/>
	</#if>
  </#list>
  </resultMap>
  
  <!-- ${table.tableComment}分页查询 -->
  <select id="getListByBoPage"  resultMap="BaseResultMap">
	SELECT
	<#list columnList as column>
		${column.columnName}<#if column_has_next>,</#if>
  	</#list>
	FROM
		${table.tableName}
	WHERE
		enabled = 1
	<#list columnList as column>
	<#if column.propertyDataType == 'int'>
	<if test="bo.${column.propertyName} != 0">
		AND ${column.columnName} = ${xmlDataPre}bo.${column.propertyName}${xmlDataSur}
	</if>
	</#if>
	<#if column.propertyDataType == 'Long'>
	<if test="bo.${column.propertyName} != null">
		AND ${column.columnName} = ${xmlDataPre}bo.${column.propertyName}${xmlDataSur}
	</if>
	</#if>
	<#if column.propertyDataType == 'Date'>
		AND ${column.columnName} = ${xmlDataPre}bo.${column.propertyName}${xmlDataSur}
	</#if>
	<#if column.propertyDataType == 'String'>
	<if test="bo.${column.propertyName} != null and bo.${column.propertyName} != ''">
		AND ${column.columnName} = ${xmlDataPre}bo.${column.propertyName}${xmlDataSur}
	</if>	
	</#if>
	</#list>
	ORDER BY create_time desc
  </select>
  
  <!-- 批量删除 -->
  <update id="deleteByPrimaryKey" parameterType="${columnPriKey.propertyDataType}" >
    UPDATE ${table.tableName} 
    	SET enabled = 0
    	WHERE
    		enabled = 1
    	AND code in 
    	<foreach collection="codes" index="index" item="item" open="("
			separator="," close=")">
			${xmlDataPre}item${xmlDataSur}
   	 	</foreach>
  </update>
  
  <!-- 新增插入 -->
  <insert id="insert" parameterType="${config.modelConfig.packageUrl}.${table.modelName}" useGeneratedKeys="true" keyColumn="id">
    INSERT INTO ${table.tableName} (
    <#list columnList as column>
    <#if column.columnKey!='PRI'>
		${column.columnName}<#if column_has_next>,</#if>
	</#if>
  	</#list>
    )
    VALUES (
    <#list columnList as column>
    <#if column.columnKey!='PRI'>
		${xmlDataPre}${column.propertyName}${xmlDataSur}<#if column_has_next>,</#if>
	</#if>
  	</#list>
    )
  </insert>
  
  <!-- 更新 -->
  <update id="updateByPrimaryKey" parameterType="${config.modelConfig.packageUrl}.${table.modelName}" >
    UPDATE ${table.tableName}
    	SET 
	    <#list columnList as column>
	   	<#if column.columnKey!='PRI'> 
	   		<#if column.propertyDataType == 'int'>
   			<if test="${column.propertyName} != 0">
				${column.columnName} = ${xmlDataPre}${column.propertyName}${xmlDataSur}<#if column_has_next>,</#if>
			</if>
	   		</#if>
	   		<#if column.propertyDataType == 'Long'>
	   		<if test="${column.propertyName} != null">
				${column.columnName} = ${xmlDataPre}${column.propertyName}${xmlDataSur}<#if column_has_next>,</#if>
			</if>
	   		</#if>
	   		<#if column.propertyDataType == 'Date'>
				${column.columnName} = ${xmlDataPre}${column.propertyName}${xmlDataSur}<#if column_has_next>,</#if>
	   		</#if>
	   		<#if column.propertyDataType == 'String'>
	   		<if test="${column.propertyName} != null and ${column.propertyName} != ''">
				${column.columnName} = ${xmlDataPre}${column.propertyName}${xmlDataSur}<#if column_has_next>,</#if>
			</if>	
	   		</#if>
		</#if>
	  	</#list>
    WHERE code = ${xmlDataPre}code${xmlDataSur}
  </update>
  
</mapper>